import cv2
import numpy as np
from torchvision.datasets import VOCDetection

"""
数据集的下载
"""

if __name__ == "__main__":
    datasets = VOCDetection("./data", year="2007", image_set='trainval', download=False)
    # 查看dataset中图片数量
    print('the pic count num is'.format(len(datasets)))

    # 取出其中一个sample来看看
    item_id = 1
    img, target = datasets.__getitem__(item_id)
    print("the image(shape:{}) {}'s target is \n {}".format(np.array(img).shape, item_id, target))

    # 查看图像
    cv2.imshow('image{}'.format(item_id), np.array(img))
    # 阻塞等待,以免闪退
    cv2.waitKey()